local rule = fk.CreateSkill {
  name = "#1v1_rule&",
}

local function formatGeneral(gname)
  local splited = gname:split("__")
  local ret = Fk:translate(gname, "zh_CN")
  if splited[1] ~= gname then
    ret = ret .. "<" .. Fk:translate(splited[1], "zh_CN") .. ">"
  end
  return ret
end

-- 发送一条log而已
rule:addEffect(fk.GameFinished, {
  priority = -1,
  can_refresh = function (self, event, target, player, data)
    return data and data ~= "" and player == RoomInstance.current
  end,
  on_refresh = function (self, event, target, player, data)
    local room = RoomInstance
    local winners = data:split("+")
    winners = table.filter(room.alive_players, function(p) ---@type ServerPlayer[]
      return table.contains(winners, p.role)
    end)
    local logString = ">>> 房间#%d的一局单挑结束 先手=%s 后手=%s 胜利者=%s 本局用时=%d秒"
    local lord = room:getLord() --[[@as ServerPlayer]]
    local rebel = lord.next
    local winner = winners[1] == lord and "先手" or "后手"
    fk.qInfo(logString:format(room.id, formatGeneral(lord.general), formatGeneral(rebel.general), winner, os.time() - room.start_time ))
  end,
})

return rule

